from sklearn.datasets import load_iris                    #导入鸢尾花数据集
from sklearn.model_selection import train_test_split      #train_test_split函数用于数据切分。其输入为待切分的特征X和相应变量y
from sklearn.neighbors import KNeighborsClassifier as KNN #KNN近邻算法
if __name__ == '__main__':
    iris = load_iris()
    x_train,x_test,y_train,y_test = train_test_split(
        iris.data[:,[1,3]],iris.target)                   #花萼宽度(2)与花瓣宽度(4);样本比例与随机种子省略
    model = KNN()
    model.fit(x_train,y_train)

train_score = model.score(x_train,y_train)
test_score = model.score(x_test,y_test)
print("train_score:",train_score)
print("test_score:",test_score)
